// const path = require('path')
// const fs = require('fs')
const chalk = require('chalk')
// const ora = require('ora')

const envKey = process.argv[2] || 'development'
// let spinner = null

process.env.NODE_ENV = envKey
//npm run clean && npm run syncCfg development && npm run syncModules development
// spinner = ora(chalk.cyan('Doing npm common job for env : ' + envKey + '\n'))
// spinner.start()
// console.info(chalk.cyan('Doing npm common job for env : ' + envKey + '\n'))

function cleanDist() {
  let { execSync } = require('child_process')
  let cmd = 'npm run clean'

  // spinner = ora('Clean dist file')

  execSync(cmd)
  console.log(chalk.green('Clean dist file success.'))
}

function syncCfg() {
  let { execSync } = require('child_process')
  let cmd = `npm run syncCfg ${envKey}`

  // spinner = ora('Sync cfg file')
  execSync(cmd)
  console.log(chalk.green('Sync cfg file success.'))
}

function runNpmCommon() {
  cleanDist()
  syncCfg()
  // spinner.stop()
}

runNpmCommon()
